package top.suven.base.http.admin.log.dao;

import org.apache.ibatis.annotations.*;
import top.suven.base.core.mybatis.crud.CommonCrudMapper;
import top.suven.base.http.admin.log.model.LoginInfo;
import top.suven.base.http.admin.log.model.LoginLog;

import java.util.List;

/**
 * @Title: LoginLogWebDao.java
 * @Description: 登录日志的数据交互类
 * @author lixiangling
 * @date   2018/08/28 11:12:22
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
public interface LoginLogWebDao extends CommonCrudMapper<LoginLog> {
    @Select("<script> " +
    "select * from  sys_login_log where status='1' and enable_status='1' and log_id in " +
    "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
    "#{item} " +
    "</foreach> " +
    "</script>")
    @Results(
        id="loginLog",
        value = {
            @Result(column = "log_id" , property = "logId"),
			@Result(column = "log_type" , property = "logType"),
			@Result(column = "user_id_tmp" , property = "userIdTmp"),
			@Result(column = "login_time" , property = "loginTime"),
			@Result(column = "logout_time" , property = "logoutTime"),
			@Result(column = "login_type" , property = "loginType"),
			@Result(column = "ip_address" , property = "ipAddress"),
			@Result(column = "mac_id" , property = "macId"),
			@Result(column = "status" , property = "status"),
			@Result(column = "creater" , property = "creater"),
			@Result(column = "create_time" , property = "createTime"),
			@Result(column = "modifier" , property = "modifier"),
			@Result(column = "modify_time" , property = "modifyTime"),
			@Result(column = "reorder" , property = "reorder"),
			@Result(column = "remark" , property = "remark"),
			@Result(column = "enable_status" , property = "enableStatus"),
			@Result(column = "user_id" , property = "userId"),
			@Result(column = "client_type" , property = "clientType"),
			@Result(column = "imei" , property = "imei"),
			@Result(column = "mobile_model" , property = "mobileModel"),
			@Result(column = "os_type" , property = "osType"),
			@Result(column = "user_source" , property = "userSource"),
			@Result(column = "version" , property = "version"),
			@Result(column = "cuid" , property = "cuid")
        }
    )
    List<LoginLog> getSysRoleMenuByRoleCodeList(@Param("idList") List<Long> idList);
    /**
     * @Title: 删除登录日志信息
     * @Description:id @{Link Long[]}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/28 11:12:22
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Update("<script> " +
            "UPDATE sys_login_log set status='0'"+
            "WHERE log_id IN " +
            "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    void del(@Param("idList") List<Long> idList);
    /**
     * @Title: 禁用登录日志信息
     * @Description:id @{Link Long}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/28 11:12:22
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
     @Update("<script> " +
             "UPDATE sys_login_log  " +
             "SET log_id = #{enableStatus}  " +
             "WHERE user_id IN " +
             "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
             "#{item} " +
             "</foreach> " +
             "</script>")
     void updateEnableStatus(@Param("enableStatus") String enableStatus, @Param("idList") List<Long> idList);

	 @Select("<script> " +
			"select client_type as clientType,count(distinct user_id) as count from sys_login_log "+
			 "where login_time  BETWEEN to_timestamp(to_char(current_timestamp- interval '1 day', 'yyyy-MM-dd 00:00:00'),'yyyy-MM-dd HH24:mi:ss') "+
			"and to_timestamp(to_char(current_timestamp, 'yyyy-MM-dd 00:00:00'),'yyyy-MM-dd HH24:mi:ss') "+
			"group by client_type  "+
			"</script>")
	 List<LoginInfo> getLoginInfoClient();
	 @Select("<script> " +
			"select to_char(login_time, 'yyyy-MM-dd') as LoginTime,count(0) as count from sys_login_log "+
			"where login_time  BETWEEN to_timestamp(to_char(current_timestamp- interval '2 day', 'yyyy-MM-dd 00:00:00'),'yyyy-MM-dd HH24:mi:ss') "+
			"and to_timestamp(to_char(current_timestamp, 'yyyy-MM-dd 00:00:00'),'yyyy-MM-dd HH24:mi:ss') "+
			"group by to_char(login_time, 'yyyy-MM-dd')  "+
			"order by to_char(login_time, 'yyyy-MM-dd') "+
			"</script>")
	 List<LoginInfo> getLoginInfoRateOfRise();
}